//
//  DatePickView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/27.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "DatePickView.h"

@interface DatePickView()

@property (strong, nonatomic) UIView *blckView;

@end


@implementation DatePickView

+(instancetype)createView
{
    return [[[NSBundle mainBundle]loadNibNamed:@"DatePickView" owner:nil options:nil]lastObject];
}


-(void)showInView:(UIView*)view{
    
    
    if (!self.blckView) {
        self.blckView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        [self.blckView setBackgroundColor:[UIColor blackColor]];
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [self.blckView addGestureRecognizer:singleTap];
    }
    
    
    
    CGRect buf = self.frame;
    buf.size.width = view.frame.size.width;
    buf.origin.y = view.frame.size.height;
    [self setFrame:buf];
    
    [self.blckView setAlpha:0];
    
    buf.origin.y = view.frame.size.height - buf.size.height;
    [view addSubview:self.blckView];
    [view addSubview:self];
    
    [UIView animateWithDuration:0.2 animations:^{
        
        
        [self.blckView setAlpha:0.6];
        
        [self setFrame:buf];
        
        
    } completion:^(BOOL finished) {
        
    }];
}


-(void)handleSingleTap:(UITapGestureRecognizer *)sender{
    
    [self hide];
}

-(Boolean)isShow{
    
    return [self superview]!=nil;
}


-(void)hide{
    
    CGRect buf = self.frame;
    buf.origin.y += buf.size.height;
    [UIView animateWithDuration:0.2 animations:^{
        
        [self.blckView setAlpha:0];
        
        [self setFrame:buf];
        
    } completion:^(BOOL finished) {
        
        [self.blckView removeFromSuperview];
        [self removeFromSuperview];
    }];
}



@end
